from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-17 14:04:22.305452
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 17, Jan, 2022
Time: 14:04:27
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.7406
Nobs: 539.000 HQIC: -48.1767
Log likelihood: 6265.85 FPE: 9.02554e-22
AIC: -48.4569 Det(Omega_mle): 7.64929e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.370190 0.070734 5.234 0.000
L1.Burgenland 0.103177 0.042748 2.414 0.016
L1.Kärnten -0.113249 0.022100 -5.124 0.000
L1.Niederösterreich 0.190777 0.088906 2.146 0.032
L1.Oberösterreich 0.114456 0.088248 1.297 0.195
L1.Salzburg 0.265521 0.045159 5.880 0.000
L1.Steiermark 0.027587 0.059506 0.464 0.643
L1.Tirol 0.105744 0.047981 2.204 0.028
L1.Vorarlberg -0.076150 0.042433 -1.795 0.073
L1.Wien 0.018352 0.078200 0.235 0.814
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067879 0.154599 0.439 0.661
L1.Burgenland -0.044127 0.093430 -0.472 0.637
L1.Kärnten 0.040543 0.048301 0.839 0.401
L1.Niederösterreich -0.204732 0.194314 -1.054 0.292
L1.Oberösterreich 0.448049 0.192877 2.323 0.020
L1.Salzburg 0.287147 0.098700 2.909 0.004
L1.Steiermark 0.111715 0.130057 0.859 0.390
L1.Tirol 0.307551 0.104868 2.933 0.003
L1.Vorarlberg 0.020644 0.092742 0.223 0.824
L1.Wien -0.025578 0.170917 -0.150 0.881
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.196572 0.036183 5.433 0.000
L1.Burgenland 0.091108 0.021867 4.167 0.000
L1.Kärnten -0.007545 0.011305 -0.667 0.504
L1.Niederösterreich 0.235720 0.045478 5.183 0.000
L1.Oberösterreich 0.164326 0.045142 3.640 0.000
L1.Salzburg 0.040278 0.023100 1.744 0.081
L1.Steiermark 0.025440 0.030439 0.836 0.403
L1.Tirol 0.081991 0.024544 3.341 0.001
L1.Vorarlberg 0.054322 0.021706 2.503 0.012
L1.Wien 0.119356 0.040002 2.984 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.123453 0.036220 3.408 0.001
L1.Burgenland 0.042111 0.021889 1.924 0.054
L1.Kärnten -0.014129 0.011316 -1.249 0.212
L1.Niederösterreich 0.172732 0.045525 3.794 0.000
L1.Oberösterreich 0.331935 0.045188 7.346 0.000
L1.Salzburg 0.103054 0.023124 4.457 0.000
L1.Steiermark 0.109831 0.030471 3.604 0.000
L1.Tirol 0.091345 0.024569 3.718 0.000
L1.Vorarlberg 0.056634 0.021728 2.606 0.009
L1.Wien -0.017473 0.040043 -0.436 0.663
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112793 0.068623 1.644 0.100
L1.Burgenland -0.041538 0.041472 -1.002 0.317
L1.Kärnten -0.045271 0.021440 -2.112 0.035
L1.Niederösterreich 0.142518 0.086252 1.652 0.098
L1.Oberösterreich 0.166807 0.085614 1.948 0.051
L1.Salzburg 0.280384 0.043811 6.400 0.000
L1.Steiermark 0.064048 0.057730 1.109 0.267
L1.Tirol 0.153950 0.046549 3.307 0.001
L1.Vorarlberg 0.094760 0.041166 2.302 0.021
L1.Wien 0.075411 0.075867 0.994 0.320
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.092732 0.053366 1.738 0.082
L1.Burgenland 0.020079 0.032251 0.623 0.534
L1.Kärnten 0.052409 0.016673 3.143 0.002
L1.Niederösterreich 0.191051 0.067076 2.848 0.004
L1.Oberösterreich 0.321843 0.066579 4.834 0.000
L1.Salzburg 0.039399 0.034070 1.156 0.248
L1.Steiermark -0.001767 0.044895 -0.039 0.969
L1.Tirol 0.124048 0.036200 3.427 0.001
L1.Vorarlberg 0.063487 0.032014 1.983 0.047
L1.Wien 0.097948 0.058999 1.660 0.097
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165830 0.064600 2.567 0.010
L1.Burgenland 0.009088 0.039040 0.233 0.816
L1.Kärnten -0.065222 0.020183 -3.232 0.001
L1.Niederösterreich -0.110261 0.081195 -1.358 0.174
L1.Oberösterreich 0.213584 0.080594 2.650 0.008
L1.Salzburg 0.051242 0.041242 1.242 0.214
L1.Steiermark 0.255132 0.054345 4.695 0.000
L1.Tirol 0.497160 0.043820 11.346 0.000
L1.Vorarlberg 0.065581 0.038752 1.692 0.091
L1.Wien -0.078245 0.071418 -1.096 0.273
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167675 0.071476 2.346 0.019
L1.Burgenland -0.008946 0.043196 -0.207 0.836
L1.Kärnten 0.062633 0.022331 2.805 0.005
L1.Niederösterreich 0.175563 0.089837 1.954 0.051
L1.Oberösterreich -0.068437 0.089173 -0.767 0.443
L1.Salzburg 0.208169 0.045632 4.562 0.000
L1.Steiermark 0.137365 0.060129 2.285 0.022
L1.Tirol 0.055733 0.048484 1.150 0.250
L1.Vorarlberg 0.143468 0.042877 3.346 0.001
L1.Wien 0.129737 0.079020 1.642 0.101
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.396226 0.041745 9.492 0.000
L1.Burgenland -0.002709 0.025228 -0.107 0.914
L1.Kärnten -0.020616 0.013042 -1.581 0.114
L1.Niederösterreich 0.203282 0.052469 3.874 0.000
L1.Oberösterreich 0.237988 0.052081 4.570 0.000
L1.Salzburg 0.035024 0.026651 1.314 0.189
L1.Steiermark -0.016614 0.035118 -0.473 0.636
L1.Tirol 0.086834 0.028317 3.067 0.002
L1.Vorarlberg 0.050271 0.025042 2.007 0.045
L1.Wien 0.033907 0.046151 0.735 0.463
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.033573 0.098322 0.163403 0.136366 0.085784 0.081432 0.027591 0.208796
Kärnten 0.033573 1.000000 -0.026454 0.133304 0.048152 0.083783 0.447148 -0.070154 0.093363
Niederösterreich 0.098322 -0.026454 1.000000 0.307772 0.123794 0.264946 0.065048 0.157491 0.279713
Oberösterreich 0.163403 0.133304 0.307772 1.000000 0.217750 0.292989 0.170422 0.133216 0.232173
Salzburg 0.136366 0.048152 0.123794 0.217750 1.000000 0.127970 0.085744 0.107894 0.126801
Steiermark 0.085784 0.083783 0.264946 0.292989 0.127970 1.000000 0.137858 0.104048 0.027777
Tirol 0.081432 0.447148 0.065048 0.170422 0.085744 0.137858 1.000000 0.064929 0.149089
Vorarlberg 0.027591 -0.070154 0.157491 0.133216 0.107894 0.104048 0.064929 1.000000 -0.006290
Wien 0.208796 0.093363 0.279713 0.232173 0.126801 0.027777 0.149089 -0.006290 1.000000